import { defHttp } from '/@/utils/http/axios';
import { createVNode } from 'vue';
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import { Modal, message } from 'ant-design-vue';

export const API = {
  // 站点列表分页
  page: '/station/page',
  // 站点列表
  list: '/station/list',
  // 站点删除
  delete: '/station/delete',
  // 站点详情
  info: '/station/info',
  // 新增站点信息
  add: '/station/add',
  // 修改站点信息
  modify: '/station/modify',
  // 更新PIC图
  updateGraph: '/station/update-graph',
  // 区域镇街列表
  regionList: '/region/list'
}

/**
 * 获取区域镇街列表
 */
export const getRegionList = async () => {
  return await defHttp.get({ url: API.regionList });
}


/**
 * 获取站点分页列表
 * @param {int} current 当前页
 * @param {int} size 当前页总数
 * @returns
 */
export const stationPageApi = async (params) => {
  return await defHttp.get({ url: API.page, params });
}

/**
 * 根据ID获取站点详情
 * @returns
 */
export const stationInfoApi = async (params) => {
  return await defHttp.get({ url: API.info, params });
}

/**
 * 获取站点列表
 * @returns
 */
export const stationListApi = async (params) => {
  return await defHttp.get({ url: API.list, params });
}

/**
 * 站点编辑 文档地址 {@link http://192.168.1.52:8080/api/doc.html#/default/%E7%AB%99%E7%82%B9/modifyUsingPOST}
 * @param {String} name 名称
 * @param {String} address 地址
 * @param {String} contect 联系人
 * @param {String} longitue 经度
 * @param {String} latitude 纬度
 * @param {String} stationCode 站点编码
 * @param {String} stationSubtype 站点主体类型
 * @param {String} stationType 站点类型
 * @param {String} tel 电话号码
 * @returns
 */
export const stationAddApi = async (data) => {
  return new Promise((resolve, reject) => {
    Modal.confirm({
      title: '提示',
      icon: createVNode(ExclamationCircleOutlined),
      content: '确定提交当前数据?',
      centered: true,
      async onOk() {
        await defHttp.post({ url: API.add, data }).then((res) => {
          resolve(res);
        })
      }, onCancel() {
        message.warning('已取消');
        resolve('')
      },
    });
  })
}

/**
 * 站点编辑 文档地址 {@link http://192.168.1.52:8080/api/doc.html#/default/%E7%AB%99%E7%82%B9/modifyUsingPOST}
 * @param {String} name 名称
 * @param {String} address 地址
 * @param {String} contect
 * @param {String} longitue 经度
 * @param {String} latitude 纬度
 * @param {String} stationCode 站点编码
 * @param {String} stationSubtype 站点主体类型
 * @param {String} stationType 站点类型
 * @param {String} tel 电话号码
 * @returns
 */
export const stationModifyApi = async (data) => {
  return new Promise((resolve, reject) => {
    Modal.confirm({
      title: '提示',
      icon: createVNode(ExclamationCircleOutlined),
      content: '确定提交当前数据?',
      centered: true,
      async onOk() {
        await defHttp.post({ url: API.modify, data }).then((res) => {
          resolve(res);
        })
      }, onCancel() {
        message.warning('已取消');
        resolve('')
      },
    });
  })
}

/**
 * 删除站点接口
 * @param {*} id
 * @returns
 */
export const stationDeleteApi = (data) => {
  return new Promise((resolve, reject) => {
    Modal.confirm({
      title: '提示',
      icon: createVNode(ExclamationCircleOutlined),
      content: '确定删除当前站点数据?',
      centered: true,
      onOk() {
        resolve(defHttp.post({ url: API.delete, data }))
      }, onCancel() {
        message.warning('已取消');
        reject();
      },
    });
  })
}

/**
 * 更新plc图 {@link http://192.168.1.66:38080/api/doc.html#/default/%E7%AB%99%E7%82%B9/updateGraphUsingPOST}
 * @param {String} id
 * @param {String} graph PIC图
 * @returns
 */
export const updateGraphApi = (data) => {
  return new Promise(async (resolve, reject) => {
    await defHttp.post({ url: API.updateGraph, data }).then((res) => {
      message.success('保存成功');
      resolve(res);
    }).catch(() => {
      message.error('保存失败');
      reject();
    })
  })
}

export default {
  pageUrl: API.page,
}